"""
@name : 10.python常见魔术方法
@author : wenyao
@projectname: xsfh
"""
#构造方法
#__new__  创建实例
#__init__  实例进行初始化

#析构方法(__del__)
#实例销毁或者释放的时候自动执行

#############with语句
# class A:
#     def __del__(self):
#         print("this is A.del")
#
# a1 = A()
# del a1
# print("xxxxxxxxxxxxxxxxx")

#####调用方法 __call__
#把实例化之后的对象当作函数来自动调用

# class ATM:
#     def __call__(self,name):
#         print(f"i am ATM.call,my name is {name}")
# a1 = ATM()
# a1("sc1")


########
#__str__  __repr__
#对象的描述信息
#__str__ 给用户看的，默认调用__repr__
#__repr__ 给程序员看的，更加官方一点的说明
# >>> class A:
# ...     def __str__(self):
# ...         return "str...A"
# ...     def __repr__(self):
# ...         return "repr...A"
# ...
# >>> a1 = A()
# >>> print(a1)
# str...A
# >>> a1
# repr...A
# >>> class A:
# ...     def __repr__(self):
# ...         return "repr...A"
# ...
# >>> a1 = A()
# >>> print(a1)
# repr...A

#
#__getitem__
#__setitem__
#__delitem__
#对象以字典的形式去设置或者获取参数
# class A:
#     def __init__(self):
#         self.data = {}
#
#     def __getitem__(self,key):
#         print("get data:")
#         return  self.data.get(key,0)
#
#     def __setitem__(self,key, value):
#         print("set data:",key,value)
#         self.data[key] = value
#
#     def __delitem__(self,key):
#         print("delete data")
#         del(self.data[key])
#
# a1 = A()
# print(a1["key1"])
# a1["key1"] = "mangguochaomei"
# print(a1["key1"])
# del a1["key1"]

# class A:
#     def __init__(self,num):
#         self.num = num
#     def __add__(self,x):
#         print("this is add")
#         return self.num +x
# a1 = A(3)
# print(a1 + 6)

